
#include "awdb.hpp"
#include <iostream>

awdb::Data::~Data( void )
{
	AWDB_close( &awdb );
	return;
}

awdb::Data::Data( const std::string &database_filename )
{
	AWDB_file_open( database_filename.c_str(), &awdb );
	return;
}

int awdb::Data::locate(const std::string &ip_address){

    AIWEN_result result = AWDB_reader_find(&awdb, ip_address.c_str());
    if(awdb.file_size < result.entry.offset){
        std::cout << "Invalid node_index in search tree\n" << std::endl;
        return 0;
    }
    int stat;
    if (result.is_found == true) {
        AWDB_resolve(stdout, &awdb, &result);
        stat = 1;
    } else {
        printf("没有相关数据\n");
        stat = 0;
    }
    return stat;
}

